package query

import (
	"github.com/romberli/das/pkg/message"
	"github.com/romberli/go-util/config"
)

func init() {
	initQueryDebugMessage()
	initQueryInfoMessage()
	initQueryErrorMessage()
}

const (
	// debug
	DebugQueryGetByMySQLClusterID                           = 104001
	DebugQueryGetByMySQLServerID                            = 104002
	DebugQueryGetByHostInfo                                 = 104003
	DebugQueryGetByMySQLServerAndMonitorSystemInfo          = 104004
	DebugQueryGetByDBID                                     = 104005
	DebugQueryGetByDBNameAndMySQLServerAndMonitorSystemInfo = 104006
	DebugQueryGetBySQLID                                    = 104007
	DebugQueryGetBySQLIDAndMySQLServerAndMonitorSystemInfo  = 104008
	// info
	InfoQueryGetByMySQLClusterID                           = 204001
	InfoQueryGetByMySQLServerID                            = 204002
	InfoQueryGetByHostInfo                                 = 204003
	InfoQueryGetByMySQLServerAndMonitorSystemInfo          = 204004
	InfoQueryGetByDBID                                     = 204005
	InfoQueryGetByDBNameAndMySQLServerAndMonitorSystemInfo = 204006
	InfoQueryGetBySQLID                                    = 204007
	InfoQueryGetBySQLIDAndMySQLServerAndMonitorSystemInfo  = 204008
	// error
	ErrQueryGetByMySQLClusterID                           = 404001
	ErrQueryGetByMySQLServerID                            = 404002
	ErrQueryGetByHostInfo                                 = 404003
	ErrQueryGetByMySQLServerAndMonitorSystemInfo          = 404004
	ErrQueryGetByDBID                                     = 404005
	ErrQueryGetByDBNameAndMySQLServerAndMonitorSystemInfo = 404006
	ErrQueryGetBySQLID                                    = 404007
	ErrQueryGetBySQLIDAndMySQLServerAndMonitorSystemInfo  = 104008
	ErrQueryConfigNotValid                                = 404009
	ErrQueryMonitorSystemSystemType                       = 404010
	ErrQueryCloseMonitorRepo                              = 404011
	ErrQueryCreateMonitorMysqlConnection                  = 404012
	ErrQueryCreateMonitorClickhouseConnection             = 404013
)

func initQueryDebugMessage() {
	message.Messages[DebugQueryGetByMySQLClusterID] = config.NewErrMessage(message.DefaultMessageHeader, DebugQueryGetByMySQLClusterID, "query: get by mysql cluster id. mysql_cluster_id: %d, message: %s")
	message.Messages[DebugQueryGetByMySQLServerID] = config.NewErrMessage(message.DefaultMessageHeader, DebugQueryGetByMySQLServerID, "query: get by mysql server id. mysql_server_id: %d, message: %s")
	message.Messages[DebugQueryGetByHostInfo] = config.NewErrMessage(message.DefaultMessageHeader, DebugQueryGetByHostInfo, "query: get by mysql server host info. host_ip: %s, port_num: %d, message: %s")
	message.Messages[DebugQueryGetByMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(message.DefaultMessageHeader, DebugQueryGetByMySQLServerAndMonitorSystemInfo, "query: get by mysql server and monitor system info. host_ip: %s, port_num: %d, message: %s")
	message.Messages[DebugQueryGetByDBID] = config.NewErrMessage(message.DefaultMessageHeader, DebugQueryGetByDBID, "query: get by db id. db_id: %d, message: %s")
	message.Messages[DebugQueryGetByDBNameAndMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(message.DefaultMessageHeader, DebugQueryGetByDBNameAndMySQLServerAndMonitorSystemInfo, "query: get by db name and mysql server and monitor system info. db_name: %s, host_ip: %s, port_num: %d, message: %s")
	message.Messages[DebugQueryGetBySQLID] = config.NewErrMessage(message.DefaultMessageHeader, DebugQueryGetBySQLID, "query: get by sql id. mysql_server_id: %d, sql_id: %s, message: %s")
	message.Messages[DebugQueryGetBySQLIDAndMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(message.DefaultMessageHeader, DebugQueryGetBySQLIDAndMySQLServerAndMonitorSystemInfo, "query: get by sql id and mysql server and monitor system info. sql_id: %s, host_ip: %s, port_num: %d, message: %s")
}

func initQueryInfoMessage() {
	message.Messages[InfoQueryGetByMySQLClusterID] = config.NewErrMessage(message.DefaultMessageHeader, InfoQueryGetByMySQLClusterID, "query: get by mysql cluster id completed. mysql_cluster_id: %d")
	message.Messages[InfoQueryGetByMySQLServerID] = config.NewErrMessage(message.DefaultMessageHeader, InfoQueryGetByMySQLServerID, "query: get by mysql server id completed. mysql_server_id: %d")
	message.Messages[InfoQueryGetByHostInfo] = config.NewErrMessage(message.DefaultMessageHeader, InfoQueryGetByHostInfo, "query: get by mysql server host info completed. host_ip: %s, port_num: %d")
	message.Messages[InfoQueryGetByMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(message.DefaultMessageHeader, InfoQueryGetByMySQLServerAndMonitorSystemInfo, "query: get by mysql server and monitor system info completed. host_ip: %s, port_num: %d")
	message.Messages[InfoQueryGetByDBID] = config.NewErrMessage(message.DefaultMessageHeader, InfoQueryGetByDBID, "query: get by db id completed. db_id: %d.")
	message.Messages[InfoQueryGetByDBNameAndMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(message.DefaultMessageHeader, InfoQueryGetByDBNameAndMySQLServerAndMonitorSystemInfo, "get by db name and mysql server and monitor system info completed. db_name: %s, host_ip: %s, port_num: %d")
	message.Messages[InfoQueryGetBySQLID] = config.NewErrMessage(message.DefaultMessageHeader, InfoQueryGetBySQLID, "query: get by sql id completed. mysql_server_id: %d, sql_id: %s")
	message.Messages[InfoQueryGetBySQLIDAndMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(message.DefaultMessageHeader, InfoQueryGetBySQLIDAndMySQLServerAndMonitorSystemInfo, "query: get by sql id and mysql server and monitor system info completed. sql_id: %s, host_ip: %s, port_num: %d")
}

func initQueryErrorMessage() {
	message.Messages[ErrQueryGetByMySQLClusterID] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryGetByMySQLClusterID, "query: get by mysql cluster id failed. mysql_cluster_id: %d")
	message.Messages[ErrQueryGetByMySQLServerID] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryGetByMySQLServerID, "query: get by mysql server id failed. mysql_server_id: %d")
	message.Messages[ErrQueryGetByHostInfo] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryGetByHostInfo, "query: get by mysql server host info failed. host_ip: %s, port_num: %d")
	message.Messages[ErrQueryGetByMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryGetByMySQLServerAndMonitorSystemInfo, "query: get by mysql server and monitor system info failed. host_ip: %s, port_num: %d")
	message.Messages[ErrQueryGetByDBID] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryGetByDBID, "query: get by db id failed. db_id: %d")
	message.Messages[ErrQueryGetByDBNameAndMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryGetByDBNameAndMySQLServerAndMonitorSystemInfo, "query: get by db name and mysql server and monitor system info failed. db_name: %s, host_ip: %s, port_num: %d")
	message.Messages[ErrQueryGetBySQLID] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryGetBySQLID, "query: get by sql id failed. mysql_server_id: %d, sql_id: %s")
	message.Messages[ErrQueryGetBySQLIDAndMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryGetBySQLIDAndMySQLServerAndMonitorSystemInfo, "query: get by sql id and mysql server and monitor system info failed. sql_id: %s, host_ip: %s, port_num: %d")
	message.Messages[ErrQueryConfigNotValid] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryConfigNotValid, "query: config is not valid. start_time: %s, end_time: %s, limit: %d")
	message.Messages[ErrQueryMonitorSystemSystemType] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryMonitorSystemSystemType, "query: monitor system type should be either 1 or 2, %d is not valid")
	message.Messages[ErrQueryCloseMonitorRepo] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryCloseMonitorRepo, "query: close monitor repo failed")
	message.Messages[ErrQueryCreateMonitorMysqlConnection] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryCreateMonitorMysqlConnection, "query: create monitor mysql connection failed. addr: %s, user: %s")
	message.Messages[ErrQueryCreateMonitorClickhouseConnection] = config.NewErrMessage(message.DefaultMessageHeader, ErrQueryCreateMonitorClickhouseConnection, "query: create monitor clickhouse connection failed. addr: %s, user: %s")
}
